<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--    <el-form-item label="会员编号" prop="memberId">-->
<!--      <el-input v-model="dataForm.memberId" placeholder="会员编号"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="会员编号" prop="memberId">
        <el-select v-model="dataForm.memberId" placeholder="请选择">
          <el-option v-for="(item,i) in memberModel" :label="item.memberNameConcatId" :value="item.memberId"></el-option>
        </el-select>
      </el-form-item>
    <el-form-item label="体温 ℃" prop="examTemp">
      <el-input v-model="dataForm.examTemp" placeholder="体温 ℃ (单位无需填写)"></el-input>
    </el-form-item>
    <el-form-item label="脉率 次/分钟" prop="examHr">
      <el-input v-model="dataForm.examHr" placeholder="脉率 次/分钟 (单位无需填写)"></el-input>
    </el-form-item>
    <el-form-item label="呼吸频率 次/分钟" prop="examBreath">
      <el-input v-model="dataForm.examBreath" placeholder="呼吸频率 次/分钟 (单位无需填写)"></el-input>
    </el-form-item>
    <el-form-item label="左侧血压 mmHg" prop="examLeftbloo">
      <el-input v-model="dataForm.examLeftbloo" placeholder="左侧血压 mmHg (单位无需填写)"></el-input>
    </el-form-item>
    <el-form-item label="右侧血压 mmHg" prop="examRightbloo">
      <el-input v-model="dataForm.examRightbloo" placeholder="右侧血压 mmHg (单位无需填写)"></el-input>
    </el-form-item>
    <el-form-item label="血氧饱和度 ％" prop="examBloooxygen">
      <el-input v-model="dataForm.examBloooxygen" placeholder="血氧饱和度 ％ (单位无需填写)"></el-input>
    </el-form-item>
      <el-form-item label="饮食状况" prop="examEatstat">
        <el-select v-model="dataForm.examEatstat" placeholder="请选择">
          <el-option label="良好" value="良好"></el-option>
          <el-option label="正常" value="正常"></el-option>
          <el-option label="很好" value="很好"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="睡眠状况" prop="examSleepstate">
        <el-select v-model="dataForm.examSleepstate" placeholder="请选择">
          <el-option label="良好" value="良好"></el-option>
          <el-option label="正常" value="正常"></el-option>
          <el-option label="很好" value="很好"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="运动状况" prop="examSpotstate">
        <el-select v-model="dataForm.examSpotstate" placeholder="请选择">
          <el-option label="良好" value="良好"></el-option>
          <el-option label="正常" value="正常"></el-option>
          <el-option label="很好" value="很好"></el-option>
        </el-select>
      </el-form-item>
<!--    <el-form-item label="巡检人员编号" prop="examEmployid">-->
<!--      <el-input v-model="dataForm.examEmployid" placeholder="巡检人员"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="巡检人员编号" prop="examEmployid">
        <el-select v-model="dataForm.examEmployid" placeholder="请选择">
          <el-option v-for="(item,i) in employeeModel" :label="item.employeeNameConcatId" :value="item.employeeId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="巡检日期" prop="examDate">
        <el-date-picker
          v-model="dataForm.examDate"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    created () {
      this.getEmployeeInfo()
      this.getMemberInfo()
    },
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          memberId: '',
          examTemp: '',
          examHr: '',
          examBreath: '',
          examLeftbloo: '',
          examRightbloo: '',
          examBloooxygen: '',
          examEatstat: '',
          examSleepstate: '',
          examSpotstate: '',
          examEmployid: '',
          examDate: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          memberId: [
            { required: true, message: '会员编号不能为空', trigger: 'blur' }
          ],
          examTemp: [
            { required: true, message: '体温 ℃不能为空', trigger: 'blur' }
          ],
          examHr: [
            { required: true, message: '脉率 次/分钟不能为空', trigger: 'blur' }
          ],
          examBreath: [
            { required: true, message: '呼吸频率 次/分钟不能为空', trigger: 'blur' }
          ],
          examLeftbloo: [
            { required: true, message: '左侧血压 mmHg不能为空', trigger: 'blur' }
          ],
          examRightbloo: [
            { required: true, message: '右侧血压 mmHg不能为空', trigger: 'blur' }
          ],
          examBloooxygen: [
            { required: true, message: '血氧饱和度 ％不能为空', trigger: 'blur' }
          ],
          examEatstat: [
            { required: true, message: '饮食状况不能为空', trigger: 'blur' }
          ],
          examSleepstate: [
            { required: true, message: '睡眠状况不能为空', trigger: 'blur' }
          ],
          examSpotstate: [
            { required: true, message: '运动状况不能为空', trigger: 'blur' }
          ],
          examEmployid: [
            { required: true, message: '巡检人员不能为空', trigger: 'blur' }
          ],
          examDate: [
            { required: true, message: '巡检日期不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        },
        employeeModel: {
          employeeId: '',
          employeeNameConcatId: ''
        },
        memberModel: {
          memberId: '',
          memberNameConcatId: ''
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_healthexam/bshealthexam/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.memberId = data.bsHealthexam.memberId
                this.dataForm.examTemp = data.bsHealthexam.examTemp
                this.dataForm.examHr = data.bsHealthexam.examHr
                this.dataForm.examBreath = data.bsHealthexam.examBreath
                this.dataForm.examLeftbloo = data.bsHealthexam.examLeftbloo
                this.dataForm.examRightbloo = data.bsHealthexam.examRightbloo
                this.dataForm.examBloooxygen = data.bsHealthexam.examBloooxygen
                this.dataForm.examEatstat = data.bsHealthexam.examEatstat
                this.dataForm.examSleepstate = data.bsHealthexam.examSleepstate
                this.dataForm.examSpotstate = data.bsHealthexam.examSpotstate
                this.dataForm.examEmployid = data.bsHealthexam.examEmployid
                this.dataForm.examDate = data.bsHealthexam.examDate
                this.dataForm.createTime = data.bsHealthexam.createTime
                this.dataForm.updateTime = data.bsHealthexam.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_healthexam/bshealthexam/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'memberId': this.dataForm.memberId,
                'examTemp': this.dataForm.examTemp,
                'examHr': this.dataForm.examHr,
                'examBreath': this.dataForm.examBreath,
                'examLeftbloo': this.dataForm.examLeftbloo,
                'examRightbloo': this.dataForm.examRightbloo,
                'examBloooxygen': this.dataForm.examBloooxygen,
                'examEatstat': this.dataForm.examEatstat,
                'examSleepstate': this.dataForm.examSleepstate,
                'examSpotstate': this.dataForm.examSpotstate,
                'examEmployid': this.dataForm.examEmployid,
                'examDate': this.dataForm.examDate,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      //获取员工信息下拉
      getEmployeeInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllEmployee`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.employeeModel = data.date
          }
        })
      },
      //获取会员信息下拉
      getMemberInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllMember`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.memberModel = data.date
          }
        })
      }
    }
  }
</script>
